/*
 * Created by SharpDevelop.
 * user: Robertux
 * Date: 18/03/2008
 * Time: 18:22
 * 
 * 
 */

using System;
using System.Drawing;
using System.Windows.Forms;
using DataLayer;
using Inventador;

namespace WinApp
{
	/// <summary>
	/// Description of frmCambiarClave.
	/// </summary>
	public partial class frmCambiarClave : Form
	{
		private BaseDatos bdatos;
		private Usuario usr;
		
		public frmCambiarClave()
		{
			InitializeComponent();
		}
		
		public frmCambiarClave(BaseDatos bdatosExterna, int uid): this()
		{
			this.bdatos = bdatosExterna;
			this.usr = new Usuario(uid, "", "", "");
			this.usr.GetFromDb(this.bdatos);
			this.Text = "Cambiar la clave de acceso de " + this.usr.Nombre;
		}
		
		void Button1Click(object sender, EventArgs e)
		{
			this.Close();
		}
		
		void Button2Click(object sender, EventArgs e)
		{
			if(this.txtClaveAnterior.Text == "" || this.txtNuevaClave.Text == "" || this.txtRepetirClave.Text == "")
				MessageBox.Show("Todos los campos son requeridos","Error");
			else
			{
				if(this.txtClaveAnterior.Text != this.usr.Clave)
					MessageBox.Show("La clave actual del usuario no coincide con la que usted ha escrito","Error");
				else
				{
					if(this.txtNuevaClave.Text != this.txtRepetirClave.Text)
						MessageBox.Show("Las entradas de la nueva clave no coinciden","Error");
					else
					{
						this.usr.Clave = this.txtNuevaClave.Text;
						this.usr.Update(this.bdatos);
						this.Close();
					}
				}
			}
		}
	}
}
